namespace InventoryManagement
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Data.SqlClient;
	using System.Text;
	
	
	public class Modul_Detail : BaseTable
	{
		
		#region Static SQL String Members
		/// <remarks>This field represents the full SELECT string for the table Modul Detail, with the WHERE clause.</remarks>
		internal static string _SQL_Select = "SELECT [ID], [ModulName], [PathNumber], [SerialNumber], [SlotName], [ID_Network] FROM [dbo].[Modul Detail] WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the full SELECT string for the table Modul Detail, with the WHERE clause.</remarks>
		internal static string _SQL_SelectByParam = @"SELECT [ID], [ModulName], [PathNumber], [SerialNumber], [SlotName], [ID_Network] FROM [dbo].[Modul Detail] WHERE isnull(convert(varchar(36),[ID]),'true')=isnull(convert(varchar(36),@ID),isnull(convert(varchar(36),[ID]),'true')) AND isnull(convert(varchar,[ModulName]),'true')=isnull(convert(varchar,@ModulName),isnull(convert(varchar,[ModulName]),'true')) AND isnull(convert(varchar,[PathNumber]),'true')=isnull(convert(varchar,@PathNumber),isnull(convert(varchar,[PathNumber]),'true')) AND isnull(convert(varchar,[SerialNumber]),'true')=isnull(convert(varchar,@SerialNumber),isnull(convert(varchar,[SerialNumber]),'true')) AND isnull(convert(varchar,[SlotName]),'true')=isnull(convert(varchar,@SlotName),isnull(convert(varchar,[SlotName]),'true')) AND isnull(convert(varchar(36),[ID_Network]),'true')=isnull(convert(varchar(36),@ID_Network),isnull(convert(varchar(36),[ID_Network]),'true')) ";
		
		/// <remarks>This field represents the full INSERT INTO string for the table Modul Detail.</remarks>
		internal static string _SQL_Insert = "INSERT INTO [dbo].[Modul Detail] ([ID], [ModulName], [PathNumber], [SerialNumber], [SlotName], [ID_Network]) VALUES(@ID, @ModulName, @PathNumber, @SerialNumber, @SlotName, @ID_Network) ";
		
		/// <remarks>This field represents the full UPDATE string for the table Modul Detail, with the WHERE clause.</remarks>
		internal static string _SQL_Update = "UPDATE [dbo].[Modul Detail] SET [ID] = @ID, [ModulName] = @ModulName, [PathNumber] = @PathNumber, [SerialNumber] = @SerialNumber, [SlotName] = @SlotName, [ID_Network] = @ID_Network WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the DELETE string for the table Modul Detail, with the WHERE clause.</remarks>
		internal static string _SQL_Delete = "DELETE FROM [dbo].[Modul Detail] WHERE [ID]=@ID ";
		#endregion
		
		#region Tables Members
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID;
		
		[DisplayName("ID")]
		[Category("Primary Key")]
		public System.Nullable<System.Guid> ID
		{
			get
			{
				try
				{
					return _ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID", err);
				}
			}
			set
			{
				try
				{
					_ID = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _ModulName;
		
		[DisplayName("Modul Name")]
		[Category("Column")]
		public string ModulName
		{
			get
			{
				try
				{
					return _ModulName;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ModulName", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 400))
					{
						_ModulName = value;
					}
					else
					{
						throw new OverflowException("Error setting ModulName, Length of value is to long. Maximum Length: 400");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ModulName", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _PathNumber;
		
		[DisplayName("Path Number")]
		[Category("Column")]
		public string PathNumber
		{
			get
			{
				try
				{
					return _PathNumber;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting PathNumber", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_PathNumber = value;
					}
					else
					{
						throw new OverflowException("Error setting PathNumber, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting PathNumber", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _SerialNumber;
		
		[DisplayName("Serial Number")]
		[Category("Column")]
		public string SerialNumber
		{
			get
			{
				try
				{
					return _SerialNumber;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting SerialNumber", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_SerialNumber = value;
					}
					else
					{
						throw new OverflowException("Error setting SerialNumber, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting SerialNumber", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _SlotName;
		
		[DisplayName("Slot Name")]
		[Category("Column")]
		public string SlotName
		{
			get
			{
				try
				{
					return _SlotName;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting SlotName", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 400))
					{
						_SlotName = value;
					}
					else
					{
						throw new OverflowException("Error setting SlotName, Length of value is to long. Maximum Length: 400");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting SlotName", err);
				}
			}
		}
		
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID_Network;
		
		[DisplayName("ID_Network")]
		[Category("Foreign Key")]
		public System.Nullable<System.Guid> ID_Network
		{
			get
			{
				try
				{
					return _ID_Network;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_Network", err);
				}
			}
			set
			{
				try
				{
					_ID_Network = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_Network", err);
				}
			}
		}
		#endregion
		
		#region Related Objects
		/// <remarks>Represents the foreign key object</remarks>
		private Inventory_Network _ID_Network_Inventory_Network;
		
		[Description("Represents the foreign key object of the type Inventory_Network")]
		public Inventory_Network ID_Network_Inventory_Network
		{
			get
			{
				try
				{
					return _ID_Network_Inventory_Network;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_Network_Inventory_Network", err);
				}
			}
			set
			{
				try
				{
					_ID_Network_Inventory_Network = value;
					_ID_Network = _ID_Network_Inventory_Network.ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_Network_Inventory_Network", err);
				}
			}
		}
		#endregion
		
		#region Public Methods
		public void Select()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Modul_Detail._SQL_Select;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataReader rs = Com.ExecuteReader();
				while(rs.Read())
				{
					AddFromRecordSet(rs);
				}
				rs.Close();
				Conn.Close();
				rs.Dispose();
				Com.Dispose();
				Conn.Dispose();
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public System.Data.DataTable SelectByParam()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Modul_Detail._SQL_SelectByParam;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataAdapter objDataAdapter = new SqlDataAdapter(Com);
				DataTable objDataTable = new DataTable();
				objDataAdapter.Fill(objDataTable);
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return objDataTable;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Insert()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Modul_Detail._SQL_Insert;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Update()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Modul_Detail._SQL_Update;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Delete()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Modul_Detail._SQL_Delete;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public string[] GetSqlCommandStrings()
		{
			try
			{
				string[] CommStr = new string[4];
				CommStr[0] = "SELECT [ID], [ModulName], [PathNumber], [SerialNumber], [SlotName], [ID_Network] FROM [dbo].[Modul Detail] WHERE [ID] = " + _ID + "";
				CommStr[1] = "INSERT INTO [dbo].[Modul Detail] ([ID], [ModulName], [PathNumber], [SerialNumber], [SlotName], [ID_Network]) VALUES(" + _ID + ", '" + _ModulName.Replace("'","''") + "', '" + _PathNumber.Replace("'","''") + "', '" + _SerialNumber.Replace("'","''") + "', '" + _SlotName.Replace("'","''") + "', " + _ID_Network + ")";
				CommStr[2] = "UPDATE [dbo].[Modul Detail] SET [ModulName] = '" + _ModulName.Replace("'","''") + "' ,[PathNumber] = '" + _PathNumber.Replace("'","''") + "' ,[SerialNumber] = '" + _SerialNumber.Replace("'","''") + "' ,[SlotName] = '" + _SlotName.Replace("'","''") + "' ,[ID_Network] = " + _ID_Network + " WHERE [ID] = " + _ID + "";
				CommStr[3] = "DELETE FROM [dbo].[Modul Detail] WHERE [ID] = " + _ID + "";
				return CommStr;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		#endregion
		
		#region Private Methods
		private void AddFromRecordSet(SqlDataReader rs)
		{
			try
			{
				// if value from the recordset, to the ID field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID")) == false))
				{
					ID = rs.GetGuid(rs.GetOrdinal("ID"));
				}
				// if value from the recordset, to the ModulName field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ModulName")) == false))
				{
					ModulName = rs.GetString(rs.GetOrdinal("ModulName"));
				}
				// if value from the recordset, to the PathNumber field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("PathNumber")) == false))
				{
					PathNumber = rs.GetString(rs.GetOrdinal("PathNumber"));
				}
				// if value from the recordset, to the SerialNumber field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("SerialNumber")) == false))
				{
					SerialNumber = rs.GetString(rs.GetOrdinal("SerialNumber"));
				}
				// if value from the recordset, to the SlotName field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("SlotName")) == false))
				{
					SlotName = rs.GetString(rs.GetOrdinal("SlotName"));
				}
				// if value from the recordset, to the ID_Network field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID_Network")) == false))
				{
					ID_Network = rs.GetGuid(rs.GetOrdinal("ID_Network"));
				}
			}
			catch (SqlException sqlExc)
			{
				throw sqlExc;
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		
		private SqlParameter[] GetSqlParameters()
		{
			List<SqlParameter> SqlParmColl = new List<SqlParameter>();
			try
			{
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID", ID, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ModulName", ModulName, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@PathNumber", PathNumber, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@SerialNumber", SerialNumber, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@SlotName", SlotName, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID_Network", ID_Network, SqlDbType.UniqueIdentifier));
				return SqlParmColl.ToArray();
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		#endregion
	}
	
	public class Modul_DetailCollection : System.Collections.CollectionBase
	{
		
		[Description("Adds a new Modul_Detail to the collection.")]
		public int Add(Modul_Detail item)
		{
			int newindex = List.Add(item);
			return newindex;
		}
		
		[Description("Removes a Modul_Detail from the collection.")]
		public void Remove(Modul_Detail item)
		{
			List.Remove(item);
		}
		
		[Description("Inserts an Modul_Detail into the collection at the specified index.")]
		public void Insert(int index, Modul_Detail item)
		{
			List.Insert(index, item);
		}
		
		[Description("Returns the index value of the Modul_Detail class in the collection.")]
		public int IndexOf(Modul_Detail item)
		{
			return List.IndexOf(item);
		}
		
		[Description("Returns true if the Modul_Detail class is present in the collection.")]
		public bool Contains(Modul_Detail item)
		{
			return List.Contains(item);
		}
	}
	
	public enum Modul_Detail_Fields
	{
		
		ID,
		
		ModulName,
		
		PathNumber,
		
		SerialNumber,
		
		SlotName,
		
		ID_Network,
	}
}
